﻿-- Author      : Kurapica
-- Create Date : 7/16/2008 14:51
     
-- StatusBar
do
	-- Check Version
	local version = 1
	if not IGAS:RegisterFile("IGAS.GUI.Widget.StatusBar", version) then
		return
	end

    local getmetatable = getmetatable
    local pairs = pairs
    local ipairs = ipairs
    local type = type
    local error = error
    local CreateFrame = CreateFrame
    
	local _WidgetName = "StatusBar"
    local _Base = "Frame"

	local _GUI = IGAS.GUI
	local _Widget = IGAS.GUI.Widget
    local _BaseFunc = IGAS.GUI.Base.Func
	local _PropertyType = IGAS.GUI.Base.PropertyType   
	
	-- ScriptType
	local _ScriptType = {
	}
    
	-- FuncProxy
	local _FuncProxy = {        
    }
    
	-- Property
	local _Property = {
        -- MinMaxValue
        ["MinMaxValue"] = {
			["Set"] = function(self, set)
				self.__UI:SetMinMaxValues(set.min, set.max)
			end,
			
			["Get"] = function(self)
				local set = {}
				set.min, set.max = self.__UI:GetMinMaxValues()
				return set
			end,
			
			["Type"] = _PropertyType.MinMaxValue,
		},
	
        -- Orientation
        ["Orientation"] = {
			["Set"] = function(self, orientation)
				self.__UI:SetOrientation(orientation)
			end,
			
			["Get"] = function(self)				
				return self.__UI:GetOrientation()
			end,
			
			["Type"] = _PropertyType.Orientation,
		},
	
		-- StatusBarColor
		["StatusBarColor"] = {
			["Set"] = function(self, colorTable)
				self.__UI:SetStatusBarColor(colorTable.red, colorTable.green, colorTable.blue, colorTable.alpha)
			end,
			
			["Get"] = function(self)
				local colorTable = {}
				colorTable.red, colorTable.green, colorTable.blue, colorTable.alpha = self.__UI:GetStatusBarColor()
				return colorTable 
			end,
			
			["Type"] = _PropertyType.Color,
		},
    
        -- StatusBarTexture
        ["StatusBarTexture"] = {
			["Set"] = function(self, texture)
				self.__UI:SetStatusBarTexture(texture)
			end,
			
			["Get"] = function(self)				
				return self.__UI:GetStatusBarTexture()
			end,
			
			["Type"] = _PropertyType.Texture,
		},
		
		-- Layer
		["Layer"] = {
			["Set"] = function(self, layer)
				self.__Layer = layer
				self.__UI:SetStatusBarTexture(self.__UI:GetStatusBarTexture(), layer)
			end,
			
			["Get"] = function(self)				
				return self.__Layer
			end,
			
			["Type"] = _PropertyType.Layer,
		},
		
        -- Value
        ["Value"] = {
			["Set"] = function(self, value)
				self.__UI:SetValue(value)
			end,
			
			["Get"] = function(self)				
				return self.__UI:GetValue()
			end,
			
			["Type"] = _PropertyType.Number,
		},
	}
	
    -- New    
    local _New = function(_parent,inheritFrame)
        -- New Frame
		local frame = CreateFrame(_WidgetName,nil,_BaseFunc.GetUI(_parent),inheritFrame)
		
        return frame
    end
	
    local _WidgetInfo = {
        ["WidgetName"] = _WidgetName,
        ["Base"] = _Base,
        ["FuncProxy"] = _FuncProxy,
        ["Property"] = _Property,
        ["ScriptType"] = _ScriptType,
        ["New"] = _New,
    }
    
    _Widget[_WidgetName] = _GUI.NewWidget(_WidgetInfo)
    
	------------------------------------------------------
	--------------- Scan new function --------------------
    ------------------------------------------------------
	local _frame = CreateFrame(_WidgetName,nil,UIParent)
	
	local _oriMeta = getmetatable(_frame)
	_oriMeta = _oriMeta.__index
    
    local _func = _Widget[_WidgetName]["FuncProxy"]
	-- Other Function
	for _f in pairs(_oriMeta) do
		if not _func[_f] and type(_oriMeta[_f]) == "function" then
			_func[_f] = function(self, ...)
                return _BaseFunc.GetVals(self.__UI[_f](self.__UI, _BaseFunc.GetArgs(...)))
			end
		end
	end
	
	-- Clear
	_oriMeta = nil
    _frame:Hide()
	_frame = nil
end